﻿using UnityEngine;
using System.Collections;

public class MovePath_2 : MovePath {

	private float cameraWidth;
	private float cameraHeight;
	// Use this for initialization
	void Start () {
		pathIndex = 0;
		pathLength = 4;

		Camera mainCamera = Camera.main;
	    cameraWidth = 2 * mainCamera.aspect * mainCamera.orthographicSize; 
		cameraHeight = 2 * mainCamera.orthographicSize;

		moveSpeed = new Vector3[pathLength];
		movePath = new Vector3[pathLength];

		moveSpeed [0].Set (0.0f,-0.01f,0.0f);
		moveSpeed [1].Set (0.01f,0.01f,0.0f);
		movePath [0].Set (0.0f,0.0f,0.0f);
		movePath [1].Set (0.5f,0.0f,0.0f);
	}
	
	// Update is called once per frame
	void Update () {
		//update position
		updatePosition ();
	}

	void updatePosition(){

		Vector3 cameraPosition = Camera.main.transform.position;

		float xDistance = movePath [pathIndex].x * cameraWidth;
		float yDistance = movePath [pathIndex].y * cameraHeight;
		Vector3 targetPosition = new Vector3(transform.position.x + xDistance,cameraPosition.y+yDistance,0);

		float xMoveOffset = moveSpeed[pathIndex].x;
		float yMoveOffset = moveSpeed[pathIndex].y;

		xMoveOffset = movePath [pathIndex].x > 0 ? xMoveOffset : 0; 
		transform.position = new Vector3(transform.position.x + xMoveOffset,transform.position.y + yMoveOffset,0);
	
//		print ("xMoveOffset = " + xMoveOffset + ",yMoveOffset = "+yMoveOffset);
//		print ("transform.position.x = " + transform.position.x + ",transform.position.y = " + transform.position.y);
//		print ("targetPosition.x = " + targetPosition.x + ",targetPosition.y = " + targetPosition.y);
		if((transform.position - targetPosition).magnitude < 0.1f){
			pathIndex++;
		}
	}
}










